






//
//  NBaseViewController.m
//  nncloud
//
//  Created by macfai on 2018/9/17.
//  Copyright © 2018年 youedata. All rights reserved.
//

#import "NBaseViewController.h"
#import "NRoleSelectedViewController.h"
#import "NLoginViewController.h"

@interface NBaseViewController ()

@end

@implementation NBaseViewController


///返回YES同时识别多个手势

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kBackgroundColor;
     [self setupNavigationBar];
    
    if (IOS7) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
    }
    
    // Do any additional setup after loading the view.
}

- (void)setupNavigationBar
{
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 26, 45);
    
    //文字
    //    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    backBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    //如果文字喝图片同时存在就把这个调整距离的打开
    //    [backBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    
    //图像
    [backBtn setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    
    [backBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -15, 0, 0)];
    [backBtn addTarget:self action:@selector(backItemClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    
    self.navigationController.navigationBar.translucent = NO;
    
//    self.navigationController.navigationBar.barTintColor = [UIColor brownColor];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
    
    //    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"导航栏背景"] forBarMetrics:UIBarMetricsDefault];
    //    self.navigationController.navigationBar.shadowImage = [UIImage imageNamed:@"下外发光"];
    
}

-(UIButton *)addNavigationLeftButtonFrame:(CGRect)frame Image:(UIImage *)normalImage AndHighLightImage:(UIImage *)highLightImage AndText:(NSString *)text Target:(id)target Action:(SEL)action
{
    
    UIButton *leftBtn                        = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame                  = frame;
    leftBtn.titleLabel.font        = kFont14;
    [leftBtn setImage:normalImage forState:UIControlStateNormal];
    [leftBtn setImage:highLightImage forState:UIControlStateHighlighted];
    [leftBtn setTitle:text forState:UIControlStateNormal];
    [leftBtn setTitle:text forState:UIControlStateHighlighted];
    [leftBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    [leftBtn setTitleColor:kWhiteColor forState:UIControlStateHighlighted];
    [leftBtn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    
    
    UIBarButtonItem *leftButtonItem       = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftButtonItem;
    
    //    UIBarButtonItem * space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //    space.width = -4;
    //    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:space,leftButtonItem, nil];
    
    self.leftBarButton = leftBtn;
    
    return leftBtn;
}

-(UIButton *)addNavgationRightButtonWithFrame:(CGRect)frame
                                        title:(NSString*)title
                                        Image:(NSString*)image
                                  selectedIMG:(NSString*)imsel
                                      tartget:(id)target
                                       action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame =frame;
    ///3s内不允许重复点击
    button.uxy_acceptEventInterval = 3.f;
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = kFont16;
    //    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitleColor:kNavigationTitleColor forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    if (imsel) {
        [button setImage:[UIImage imageNamed:imsel] forState:UIControlStateSelected];
    }
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    
    self.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    //    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
    //button.frame = CGRectMake(0, 0, 40, 30);
    self.navigationItem.rightBarButtonItem = self.rightBarButtonItem;
    return button;
}

- (void)backItemClick
{
    //解决视图上移直接点返回造成的view上移下不来的情况
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    NSArray *viewcontrollers=self.navigationController.viewControllers;
    
    if (viewcontrollers.count>1) {
        
        if ([viewcontrollers objectAtIndex:viewcontrollers.count-1]==self) {
            
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    else{
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }
    
}


-(void)callRoleSelecteVC{
    
    NRoleSelectedViewController *role = [[NRoleSelectedViewController alloc] initWithNibName:@"NRoleSelectedViewController" bundle:nil];
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:role];
    //解决present延迟弹出
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:nav animated:YES completion:^{
            
        }];
    });
}


///调起登录页面
-(void)callLoginVC{
    
    NLoginViewController *login = [[NLoginViewController alloc]initWithNibName:@"NLoginViewController" bundle:nil];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:login];
    //解决present延迟弹出
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:nav animated:YES completion:^{
            
        }];
    });
}



#pragma mark - datasource  delegate
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//    return 0;
//}
//
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return 0;
//}
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return nil;
//}

@end
